{extend name="index/iframe" /}

{block name="content"}
<form class="layui-form layui-form-my" action="">
    <input type="hidden" value="{$Think.get.id}" name="pri_id">
    <div class="layui-form-item">
        <label class="layui-form-label">权限名称</label>
        <div class="layui-input-block">
            <input type="text" name="pri_name" lay-verify="required" placeholder="请输入权限名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">接口地址</label>
        <div class="layui-input-block">
            <input type="text" name="url" lay-verify="required" placeholder="控制器/方法" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">加到菜单</label>
        <div class="layui-input-block">
            <input type="checkbox" checked="" name="is_menu" id="is_menu" lay-skin="switch" lay-filter="is_menu" lay-text="开启|关闭">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">父级菜单</label>
        <div class="layui-input-block">
            <select name="menu_id" id="menu_id" lay-search="">
                <option value="">全部</option>
                {volist name="$menu_list" id="vo"}
                <option value="{$vo.id}">{:str_repeat($vo['html'], $vo['level'])}{$vo.title}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">二级菜单</label>
        <div class="layui-input-block">
            <input type="checkbox" name="rid" id="rid" lay-skin="switch" lay-filter="rid" lay-text="开启|关闭">
        </div>
    </div>
    <div class="layui-form-item" style="margin: 50px 0 100px 0;">
        <div class="layui-input-block">
            <button class="layui-btn my-btn" lay-submit="" lay-filter="submitBtn">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}

{block name="css"}
{/block}

{block name="js"}
<script>
    layui.use(['form'], function(){
        var form = layui.form
            ,$ = layui.$
            ,layer = layui.layer;

        form.on('switch(is_menu)', function(data){
            if(data.elem.checked){
                console.dir('a');
                $('#menu_id').removeAttr('disabled');
            }else{
                $('#menu_id').attr('disabled', 'disabled');
            }
            form.render('select');
        })

        //提交
        form.on('submit(submitBtn)', function(data){
            var load = layer.load();

            $.post('{:url("SystemPrivilegeNew/add")}', data.field, function(json){
                layer.close(load);
                json.code==0 ? layer.msg(json.msg, {icon: 1, time: 1000}) : layer.msg(json.msg, {icon: 0, time: 1000});
            }, 'JSON').error(function(){
                layer.close(load);
                layer.msg('连接超时，请联系后台管理员', {icon: 2, time:3000});
            });
            return false;
        });
    });
</script>
{/block}